package com.hgyc.mom.wms.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hgyc.mom.common.vo.Result;
import com.hgyc.mom.core.mybatis.QueryWrapperUtil;
import com.hgyc.mom.wms.entity.ScmPurchaseDetail;
import com.hgyc.mom.wms.service.ScmPurchaseDetailService;
import com.hgyc.mom.wms.vo.ScmPurchaseDetailParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 采购明细Controller
 *
 * @author fwj
 * @since 2025-05-15
 */
@Tag(name = "采购明细控制器", description = "采购明细控制器")
@RestController
@RequestMapping("/wms/poDetail")
public class ScmPurchaseDetailController {
    @Autowired
    private ScmPurchaseDetailService scmPurchaseDetailService;

    @Operation(summary = "查询采购明细列表", description = "查询采购明细列表")
    @PostMapping("/list")
    public Result<List<ScmPurchaseDetail>> list(@Parameter(description = "查询参数") @RequestBody ScmPurchaseDetailParam scmPurchaseDetailParam) {
        ScmPurchaseDetail scmPurchaseDetail = new ScmPurchaseDetail();
        BeanUtils.copyProperties(scmPurchaseDetailParam, scmPurchaseDetail);
        QueryWrapper<ScmPurchaseDetail> wrapper = QueryWrapperUtil.build(scmPurchaseDetail);
        List<ScmPurchaseDetail> list = scmPurchaseDetailService.list(wrapper);
        return Result.success(list);
    }

    @Operation(summary = "获取采购明细详细信息", description = "获取采购明细详细信息")
    @GetMapping(value = "/{id}")
    public Result getInfo(@Parameter(description = "采购明细ID") @PathVariable("id") Long id) {
        return Result.success(scmPurchaseDetailService.getById(id));
    }

    @Operation(summary = "新增采购明细", description = "新增采购明细")
    @PostMapping
    public Result save(@Parameter(description = "采购明细") @RequestBody ScmPurchaseDetail scmPurchaseDetail) {
        return Result.success(scmPurchaseDetailService.save(scmPurchaseDetail));
    }

    @Operation(summary = "修改采购明细", description = "修改采购明细")
    @PutMapping
    public Result update(@Parameter(description = "采购明细") @RequestBody ScmPurchaseDetail scmPurchaseDetail) {
        return Result.success(scmPurchaseDetailService.updateById(scmPurchaseDetail));
    }

    @Operation(summary = "删除采购明细", description = "删除采购明细")
    @DeleteMapping
    public Result remove(@Parameter(description = "删除ID") @RequestParam("ids") Long[] ids) {
        return Result.success(scmPurchaseDetailService.removeByIds(Arrays.asList(ids)));
    }
}